﻿using BP.DA;
namespace BP.Sys.Printer
{
    /// <summary>
    /// 数据元素
    /// </summary>
    public class DBEle
    {
        /// <summary>
        /// 字段标记
        /// </summary>
        public string AttrKey = null;
        /// <summary>
        /// 字段名称
        /// </summary>
        public string AttrName = null;
        /// <summary>
        /// 字段值
        /// </summary>
        public object AttrValue = null;
        /// <summary>
        /// 数据类型
        /// </summary>
        public int DBDataType = DataType.AppString;
        /// <summary>
        /// 数据源的关联表单或查询
        /// </summary>
        public string RefFrmID = null;
        public DBEle() { }
    }
    /// <summary>
    /// 数据元素s
    /// </summary>
    public class DBEles : System.Collections.CollectionBase
    {
        public DBEles()
        {
        }
        /// <summary>
        /// 获得数据元素
        /// </summary>
        /// <param name="refFrmID"></param>
        /// <param name="attrKey"></param>
        /// <returns></returns>
        public DBEle GetValByKey(string refFrmID, string attrKey)
        {
            foreach (DBEle item in this)
            {
                if (item.AttrKey == attrKey && item.RefFrmID.Equals(refFrmID) == true)
                    return item;
            }
            var ele = new DBEle();
            ele.AttrKey = attrKey;
            ele.RefFrmID = refFrmID;
            ele.AttrValue = "标记[" + refFrmID + "  字段:" + attrKey + "]，不存在.";
            return ele;
        }
        public void Add(DBEle en)
        {
            this.InnerList.Add(en);
        }
        public void Add(string attrKey, string attrName, object val, int dataType, string refFrmID)
        {
            DBEle en = new DBEle();
            en.AttrKey = attrKey;
            en.AttrName = attrName;
            en.AttrValue = val;
            en.DBDataType = dataType;
            en.RefFrmID = refFrmID;
            this.InnerList.Add(en);
        }
    }

}
